# -*- coding: utf-8 -*-
"""
Created on 03 08 下午4:55 2022 
@Author : HHQUAN
@Email : 1075960398@qq.com
GAC2570读取数据的方法
"""

import  numpy as np
import matplotlib.pyplot as plt

# fid = open('/media/cl/cldata/新2570相关/2022年06_10/南望1/recfiles/rec.pcm', 'rb')
# tmp = fid.read()
# fid.close()
# data1 = np.frombuffer(tmp, dtype=np.float32, count=-1)
# data2 = np.reshape(data1, newshape=(-1, 12))
# for i in range(12):
#     files = '/media/cl/cldata/新2570相关/2022年06_10/南望1/mic'+str(i)+'.pcm'
#     fid = open(files, 'wb')
#     fid.write(data2[:, i].astype(np.int16).tobytes())
#     fid.close()


fid = open('/media/cl/cldata/新2570相关/2022年06_10/20220614/recfiles/micrec.pcm', 'rb')
tmp = fid.read()
fid.close()
data1 = np.frombuffer(tmp, dtype=np.int32, count=-1)
data2 = np.reshape(data1, newshape=(-1, 16))
sig = np.zeros((data2.shape[0], 12), dtype=np.int32)
# 回采数据
# fid = open('/media/cl/cldata/新2570相关/GAC2570_程序_20210721/gsvoice/out/bin/data52/out1.pcm', 'wb')
# fid.write((sig[:, 7]*0.1).astype(np.int16).tobytes())
# fid.close()
sig[:, 0:6] = data2[:, 0:6] # 0,1,2,3,4,5
sig[:, 6:12] = data2[:, 8:14] # 8,9,10,11,12,13
for i in range(12):
    files = '/media/cl/cldata/新2570相关/2022年06_10/20220614/mic'+str(i)+'.pcm'
    fid = open(files, 'wb')
    fid.write((sig[:, i]*0.01).astype(np.int16).tobytes())
    fid.close()






# plt.figure()
# plt.plot(data2[:, 2])
# plt.show()






